package com.a3dweijing.wetouch2.wxapi;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.a3dweijing.wetouch2.R;
import com.a3dweijing.wetouch2.Util.Util;
import com.a3dweijing.wetouch2.base.App;
import com.tencent.mm.opensdk.modelmsg.GetMessageFromWX;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXImageObject;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXWebpageObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;

/**
 * Created by Administrator on 2018/4/4.
 */

public class WXShareHelp
{
    private static final int THUMB_SIZE = 50;
    
    private static IWXAPI wxapi;
    
    // respond with image message
    Context context;
    
    public static void share(Context context, int i)
    {
        wxapi = App.getWxapi();
        WXWebpageObject webpage = new WXWebpageObject();
        webpage.webpageUrl = "http://wetouch.3dweijing.com/common/app/app-release.apk";
        WXMediaMessage msg = new WXMediaMessage(webpage);
        msg.title = "微触";
        msg.description = "app下载";
        Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
        Bitmap thumbBmp = Bitmap.createScaledBitmap(bmp, THUMB_SIZE, THUMB_SIZE, true);
        bmp.recycle();
        msg.thumbData = Util.bmpToByteArray(thumbBmp, true);
        
        SendMessageToWX.Req req = new SendMessageToWX.Req();
        req.transaction = buildTransaction("webpage");
        req.message = msg;
        req.scene = i;
        wxapi.sendReq(req);
    }
    
    private static String buildTransaction(String type)
    {
        return (type == null) ? String.valueOf(System.currentTimeMillis()) : type + System.currentTimeMillis();
    }
    
}
